<?php
    require_once '../../Database/Database.php';

    function isFinished($finished)
    {
        if($finished == 1)
        {
            return 'Ja';
        }
        else
        {
            return 'Nein';
        }
    }

    function ConvertDate($date)
    {
        return date('d.m.Y', $date);
    }
?>
<?php
    if(isset($_GET['id']))
    {
        $db = new Database();
        $db->Connect();

        $id = $_GET['id'];

        echo '<div class="add"><a href="add_race.php?id=' . $id . '" target="_blank"><img src="../../Icons/add_race.png" /></a></div>';

        $shortcut = $db->SelectColumns('Series', 'Shortcut', 'ID_Series = ' . $id);
        $races = $db->Select($shortcut[0]->Shortcut . '_calendar');

        if($races)
        {
            echo '<table><tr><td>Strecke</td><td>Datum</td><td>Beendet?</td></tr><td>';
            foreach($races as $race)
            {
                $tracks = $db->Select($shortcut[0]->Shortcut . '_tracks', 'ID_Track = ' . $race->Track_ID);

                echo $tracks[0]->Name . '</td><td>';
                echo ConvertDate($race->Start_Date) . '</td><td>';
                echo isFinished($race->Finished) . '</td></tr>';
            }
            $db->Disconnect();
            echo '</table>';
        }
        else
        {
            echo 'Keine Rennen eingetragen.';
        }
    }
    else
    {
        echo 'Ungültige Serien ID';
    }
    $db->Disconnect();
?>
